/**
 * 
 */
package com.novatialabs.qttt.gwt.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;

/**
 * @author nchalko
 * 
 */
public class GameCellWidget extends Composite implements HasClickHandlers {

  private final int cellNumber;
  private final Label stuff = new Label();

  public GameCellWidget(int cellNumber) {
    this.cellNumber = cellNumber;
    FlowPanel panel = new FlowPanel();
    panel.add(new Label(cellNumber + ""));
    panel.add(stuff);
    initWidget(panel);
  }

  public HandlerRegistration addClickHandler(ClickHandler handler) {
    return addDomHandler(handler, ClickEvent.getType());
  }

  public int getCellNumber() {

    return cellNumber;
  }

  public void display(GameModel game) {
    StringBuilder sb = new StringBuilder();
    for (Move m : game.getMoves()) {
      if (m.getFirstMark() == cellNumber) {
        sb.append("x");
      }
      stuff.setText(sb.toString());
    }

  }

}
